
/* 
 * module: login_box
 * location: sidebar_box1
 */

$sidebar_box1 = $('.span3 .row-fluid:eq(0)');

$login_box = $('.sidebar-nav#login_box');
$username_input = $login_box.find('input[name=username]');
$password_input = $login_box.find('input[name=password]');
$helper = $login_box.find('.help-inline');
$login_box.find('button#login').live('click',function() {
	$login_box.find('input').removeClass('error warning');
	$helper.removeClass('error warning').addClass('hide');
	$.post(base_url + 'index.php/frontend/login/index', $(this).parent().parent('form').serialize(), function(data) {
		if (data == 'succeed') {
			load_dashboard_box();
		} else {
			field = data.split('|')[0];
			reason = data.split('|')[1];
			level = data.split('|')[2];
			eval('$' + field + '_input').addClass(level);
			
			if (reason == 'null') {
				helper = 'Please enter your ' + field;
			} else if (reason == 'length') {
				helper = 'The length of ' + field + ' you entered is wrong';
			} else if (reason == 'pattern') {
				helper = 'Special characters are not supported in ' + field;
			} else if (reason == 'data') {
				helper = 'The ' + field + ' you entered is wrong'; 
			}
			
			$helper.removeClass('hide').addClass(level).html(helper);
		}
	});
});

function load_dashboard_box() {
	$.get(base_url + 'index.php/module/dashboard_box', function(html) {
		$sidebar_box1.html(html);
	});
	
	if (booking_progress == 'to_edit_passenger_details') {
		$main_box.unblock();
	}
}

/* 
 * module: dashboard_box
 * location: sidebar_box1
 */

$dashboard_box = $('.sidebar-nav#dashboard_box');
$dashboard_box.find('button#logout').live('click', function() {
	$.get(base_url + 'index.php/frontend/login/logout', function(data) {
		if (data == 'succeed') {
			load_login_box();
			load_homepage_block();
			$booking_box.unblock();
		}
	});
});

function load_login_box() {
	$.get(base_url + 'index.php/module/login_box', function(html) {
		$sidebar_box1.html(html);
	})
	
	if (booking_progress == 'to_edit_passenger_details') {
		//if (!unserialize($.cookie('ci_session'))['ucid']) {
			$main_box.block({
				message: '<button class="btn btn-large btn-info btn-block disabled" type="button" id="">You should login first to continue the booking process.</button>',
				css: {
					width : '65%'
				}
			});
		//}
	}
}

/* 
 * module: booking_box
 * location: sidebar_box2
 */

$sidebar_box2 = $('.span3 .row-fluid:eq(1)');

$booking_box = $('.sidebar-nav#booking_box');
$sel_airport = $booking_box.find('div.sel_airport');
$sel_itinerary_type = $booking_box.find('div.sel_itinerary_type');
$sel_date = $booking_box.find('div.sel_date');
$sel_departure_date = $booking_box.find('div.sel_date#departure_date');
$sel_return_date = $booking_box.find('div.sel_date#return_date');
$sel_passenger_count = $booking_box.find('div.sel_passenger_count');
$sel_cabin_class = $booking_box.find('div.sel_cabin_class');

function autoload_booking_box_block() {
	if ($.cookie('booking_box')) {
		
		/* sel airport */
		$sel_airport.find('select#sel_from_airport').val(JSON.parse($.cookie('booking_box')).from_airport);
		load_sel_airport({ 'type': 'to', 'fa_id': JSON.parse($.cookie('booking_box')).from_airport });
		
		$sel_airport.find('select#sel_to_airport').val(JSON.parse($.cookie('booking_box')).to_airport);
		
		/* sel itinerary type */
		$sel_itinerary_type.find('button[value="' + JSON.parse($.cookie('booking_box')).itinerary_type + '"]').addClass('active');
		if (JSON.parse($.cookie('booking_box')).itinerary_type == 'oneway') {
			$sel_return_date.find('button').addClass('disabled');
		} else {
			$sel_return_date.find('button').removeClass('disabled');
		}
		
		/* sel date */
		$sel_departure_date.find('span').html(JSON.parse($.cookie('booking_box')).departure_date);
		$sel_departure_date.find('button').attr('data-date', JSON.parse($.cookie('booking_box')).departure_date);
		
		$sel_return_date.find('span').html(JSON.parse($.cookie('booking_box')).return_date);
		$sel_return_date.find('button').attr('data-date', JSON.parse($.cookie('booking_box')).return_date);
		
		/* sel passenger count */
		$sel_passenger_count.find('select#sel_adult_count').val(JSON.parse($.cookie('booking_box')).adult_count);
		$sel_passenger_count.find('select#sel_child_count').val(JSON.parse($.cookie('booking_box')).child_count);
		$sel_passenger_count.find('select#sel_infant_count').val(JSON.parse($.cookie('booking_box')).infant_count);
		
		/* sel cabin class */
		$sel_cabin_class.find('button[value="' + JSON.parse($.cookie('booking_box')).cabin_class + '"]').addClass('active');
	}
}

var booking_progress = '';

/* sel airport */
load_sel_airport({ 'type': 'from' });

autoload_booking_box_block();

var booking_box_data =
{
	'from_airport': $sel_airport.find('select#sel_from_airport').val(),
	'to_airport': $sel_airport.find('select#sel_to_airport').val(),
	'itinerary_type': $sel_itinerary_type.find('button.active').val(),
	'departure_date': $sel_departure_date.find('span').html(),
	'return_date': $sel_return_date.find('span').html(),
	'adult_count': $sel_passenger_count.find('select#sel_adult_count').val(),
	'child_count': $sel_passenger_count.find('select#sel_child_count').val(),
	'infant_count': $sel_passenger_count.find('select#sel_infant_count').val(),
	'cabin_class': $sel_cabin_class.find('button.active').val()
};

$sel_airport.find('select#sel_from_airport').change(function() {
	//alert($(this).val());
	load_sel_airport({ 'type': 'to', 'fa_id': $(this).val() });
	
	/* for cookie */
	booking_box_data.from_airport = $(this).val();
	$.cookie('booking_box', JSON.stringify(booking_box_data));
});

$sel_airport.find('select#sel_to_airport').change(function() {
	/* for cookie */
	booking_box_data.to_airport = $(this).val();
	$.cookie('booking_box', JSON.stringify(booking_box_data));
});

/* sel itinerary type */
$sel_itinerary_type.find('button').click(function() {
	if ($(this).val() == 'oneway') {
		$sel_return_date.find('button').addClass('disabled');
	} else {
		$sel_return_date.find('button').removeClass('disabled');
	}
	
	select_flights_id = { 'departure': '', 'return': '' };
	
	/* for cookie */
	booking_box_data.itinerary_type = $(this).val();
	$.cookie('booking_box', JSON.stringify(booking_box_data));
});

/* sel date */
$sel_date.find('span').tooltip();
$sel_date.find('.datepicker button').datepicker().on('changeDate', function(ev) {
	$(this).prev('span').html(dateobj_to_str(ev.date));
	
	/* for cookie */
	booking_box_data.departure_date = $sel_departure_date.find('span').html();
	booking_box_data.return_date = $sel_return_date.find('span').html();
	$.cookie('booking_box', JSON.stringify(booking_box_data));
});

/* sel passenger count */
$sel_passenger_count.find('select').tooltip().change(function() {
	/* for cookie */
	booking_box_data.adult_count = $sel_passenger_count.find('select#sel_adult_count').val();
	booking_box_data.child_count = $sel_passenger_count.find('select#sel_child_count').val();
	booking_box_data.infant_count = $sel_passenger_count.find('select#sel_infant_count').val();
	$.cookie('booking_box', JSON.stringify(booking_box_data));
});

/* sel cabin class */
$sel_cabin_class.find('button').click(function() {
	/* for cookie */
	booking_box_data.cabin_class = $(this).val();
	$.cookie('booking_box', JSON.stringify(booking_box_data));
});

$wrapper = $('.wrapper');
$main_box = $('.span6');
$wrapper.css({ 'height': $wrapper.height() });

var effects = { 'fade_seconds': 100 };/*1000*/

$booking_box.find('button#next').live('click', function() {
	/*var post_data = { };
	post_data['from_airport'] = $sel_airport.find('select#sel_from_airport').val();
	post_data['to_airport'] = $sel_airport.find('select#sel_to_airport').val();
	post_data['itinerary_type'] = $sel_itinerary_type.find('button.active').val();
	post_data['departure_date'] = $sel_departure_date.find('span').html();
	post_data['return_date'] = $sel_return_date.find('span').html();
	post_data['adult_count'] = $sel_passenger_count.find('select#sel_adult_count').val();
	post_data['child_count'] = $sel_passenger_count.find('select#sel_child_count').val();
	post_data['infant_count'] = $sel_passenger_count.find('select#sel_infant_count').val();
	post_data['cabin_class'] = $sel_cabin_class.find('button.active').val();*/
	
	//var booking = JSON.parse($.cookie('booking_box'));
	$booking_box.block({
		message: '<button class="btn btn-small btn-info btn-block" type="button" id="modify_booking">Modify Booking Informations <br /> After pressing the button : <br /> ① Flights you have choosen is missing; <br /> ② Passengers you have typed in is missing.</button>',
		css: {
			width : '95%'
		}
	});
	load_select_flights_block('departure');
	booking_progress = 'to_select_flights';
});

function load_select_flights_block(direction) {
	$.post(base_url + 'index.php/frontend/booking/select_flights_block', { 'direction': direction }, function(html) {
		$main_box.effect('fade', {  }, effects.fade_seconds, function() {
			$main_box.html(html);
			
			//$select_flights_block.find('caption span#from_to_airport').html('hello');
			if (direction == 'departure') {
				var from_to_airport_str = $sel_airport.find('select#sel_from_airport option:selected').text() + ' → ' + $sel_airport.find('select#sel_to_airport option:selected').text();
			} else if (direction == 'return') {
				var from_to_airport_str = $sel_airport.find('select#sel_to_airport option:selected').text() + ' → ' + $sel_airport.find('select#sel_from_airport option:selected').text();
			}
			
			$('caption span#from_to_airport').html(from_to_airport_str);
			
			$main_box.css({ 'width': '710px' });
			$wrapper.css({ 'height': $main_box.height() });
			
			$wrapper.effect('size', { to: { width: 1025 } }, function() {
				$main_box.effect('fade', {  }, effects.fade_seconds);
			});
		});
	});
}

$booking_box.find('button#modify_booking').live('click', function() {
	$booking_box.unblock();
	load_homepage_block();
	booking_progress = '';
});

function load_homepage_block() {
	$.post(base_url + 'index.php/frontend/index/homepage_block', function(html) {
		$main_box.effect('fade', {  }, effects.fade_seconds, function() {
			$main_box.html(html);
			
			$main_box.css({ 'width': '607px' });
			$wrapper.css({ 'height': $main_box.height() });
			
			$wrapper.effect('size', { to: { width: 919 } }, function() {
				$main_box.effect('fade', {  }, effects.fade_seconds);
			});
		});
	});
}

/* 
 * module: select_flights_block
 * location: main_box
 */

var select_flights_id =
{
	'departure': '',
	'return': ''
};
// to_select_flights, select_flight_once, to_edit_passenger_details, wait_for_login, 
$select_flights_block = $('table#select_flights_block');

$select_flights_block.find('button#select_flight').live('click', function() {
	/* for cookie */
	if (booking_progress == 'to_select_flights') {
		booking_progress = 'select_flight_once';
		
		select_flights_id.departure = $(this).parent('td').attr('id');
		$.cookie('select_flights', JSON.stringify(select_flights_id));
		
		if (JSON.parse($.cookie('booking_box')).itinerary_type == 'oneway') {
			booking_progress = 'to_edit_passenger_details';
			//alert('单程选票成功。。。即将跳转至乘客信息收集页面');
			load_passenger_details_block();
		} else if (JSON.parse($.cookie('booking_box')).itinerary_type == 'round') {
			//alert('返程票查询中。。。');
			load_select_flights_block('return');
		}
		
	} else if (booking_progress == 'select_flight_once') {
		booking_progress = 'to_edit_passenger_details';
		
		select_flights_id['return'] = $(this).parent('td').attr('id');
		$.cookie('select_flights', JSON.stringify(select_flights_id));
		
		//alert('返程选票成功。。。即将跳转至乘客信息收集页面');
		load_passenger_details_block();
	}
});

function load_passenger_details_block() {
	$.post(base_url + 'index.php/frontend/booking/passenger_details_block', function(html) {
		$main_box.effect('fade', {  }, effects.fade_seconds, function() {
			$main_box.html(html);
			
			$main_box.css({ 'width': '710px' });
			$wrapper.css({ 'height': $main_box.height() });
			
			$wrapper.effect('size', { to: { width: 1025 } }, function() {
				$main_box.effect('fade', {  }, effects.fade_seconds);
				
				if (!unserialize($.cookie('ci_session'))['ucid']) {
					$main_box.block({
						message: '<button class="btn btn-large btn-info btn-block disabled" type="button" id="">You should login first to continue the booking process.</button>',
						css: {
							width : '65%'
						}
					});
				}
			});
		});
	});
}

/* 
 * module: passenger_details_block
 * location: main_box
 */

$passenger_information_block = $('table#passenger_information_block');

$passenger_information_block.find('input.passenger_name').live('focus', function() {
	$.cookie('current_passenger_type', $(this).parent().parent('tr').attr('class').split(' ')[0]);
}).live('keyup', function() {
	this.value = this.value.toLocaleUpperCase();
	this.value = this.value.replace(/[^A-Z]/g, '/');
	
	$ptr = $(this).parent().parent('tr');
	if ($ptr.find('input.passenger_id').val()) {
		$ptr.find('input.passenger_id').val('');
		$ptr.find('select.sel_certification_type').val('');
		$ptr.find('input.certification_number').val('');
	}
});

$passenger_information_block.find('select.sel_certification_type').live('change', function() {
	$ptr = $(this).parent().parent('tr');
	if ($ptr.find('input.passenger_id').val()) {
		$ptr.find('input.passenger_id').val('');
		$ptr.find('input.passenger_name').val('');
		$ptr.find('input.certification_number').val('');
	}
});

var passenger_ids = { };
var new_passengers_data = { };

$main_box.find('button#next').live('click', function() {
	/*$('table#passenger_information_block tbody tr').map(function() {
		alert($(this).find('input.passenger_id').val());
	});*/
	
	passenger_ids = $main_box.find('input.passenger_id').serializeArray();
	
	for (x in passenger_ids) {
		passenger_ids[x] = passenger_ids[x]['value'];
	}
	
	for (x in passenger_ids) {
		if (passenger_ids[x] == '') {
			$new_passenger_tr = $main_box.find('table#passenger_information_block tbody tr:eq(' + x + ')');
			
			new_passengers_data[x] = { };
			new_passengers_data[x]['passenger_name'] = $new_passenger_tr.find('input.passenger_name').val();
			
			if ($new_passenger_tr.attr('class').split(' ')[0] == 'adult') {
				new_passengers_data[x]['certification_type'] = $new_passenger_tr.find('select.sel_certification_type').val();
				new_passengers_data[x]['passenger_type'] = 'A';
			} else if ($new_passenger_tr.attr('class').split(' ')[0] == 'child') {
				new_passengers_data[x]['certification_type'] = 1;
				new_passengers_data[x]['passenger_type'] = 'C';
			} else {
				new_passengers_data[x]['passenger_type'] = 'I';
			}
			
			new_passengers_data[x]['certification_number'] = $new_passenger_tr.find('input.certification_number').val();
		}
	}
	
	if (new_passengers_data[0]) {
		$.post(base_url + 'index.php/backend/customer/add_new_passengers', { 'passengers_data': new_passengers_data }, function(new_passenger_ids) {
			for (x in new_passenger_ids) {
				passenger_ids[x] = new_passenger_ids[x].toString();
			}
			
			$.cookie('passenger_ids', JSON.stringify(passenger_ids));
			
			load_finish_block();
		}, 'json');
		
		new_passengers_data = { };
	} else {
		$.cookie('passenger_ids', JSON.stringify(passenger_ids));
		
		load_finish_block();
	}
});

function load_finish_block() {
	$.post(base_url + 'index.php/frontend/booking/finish_block', function(html) {
		$main_box.effect('fade', {  }, effects.fade_seconds, function() {
			$main_box.html(html);
			
			$main_box.css({ 'width': '710px' });
			$wrapper.css({ 'height': $main_box.height() });
			
			$wrapper.effect('size', { to: { width: 1025 } }, function() {
				$main_box.effect('fade', {  }, effects.fade_seconds);
			});
		});
	});
}

/* 
 * module: finish_block
 * location: main_box
 */

$finish_block = $('table#finish_block');

$main_box.find('button#confirm_order_pay_now').live('click', function() {
	alert('Your payment has been submitted successfully');
	
	$.post(base_url + 'index.php/frontend/booking/save_order', function(data) {
		if (data == 'succeed') {
			load_my_reservation_block();
			$booking_box.unblock();
		}
	});
});

/* 
 * module: my_reservation_block
 * location: main_box
 */

$dashboard_box.find('button#my_reservation').live('click', function() {
	load_my_reservation_block();
	$booking_box.unblock();
});

function load_my_reservation_block() {
	$.post(base_url + 'index.php/backend/customer/get_orders', function(html) {
		$main_box.effect('fade', {  }, effects.fade_seconds, function() {
			$main_box.html(html);
			
			$main_box.css({ 'width': '710px' });
			$wrapper.css({ 'height': $main_box.height() });
			
			$wrapper.effect('size', { to: { width: 1025 } }, function() {
				$main_box.effect('fade', {  }, effects.fade_seconds);
			});
		});
	});
}

$my_reservation_block = $('table#my_reservation_block');
$my_reservation_block.find('button#view_order_detail').live('click', function() {
	load_my_reservation_detail_block($(this).parent('td').attr('id'));
});

function load_my_reservation_detail_block(order_id) {
	$.post(base_url + 'index.php/backend/customer/get_order_detail/' + order_id, function(html) {
		$main_box.effect('fade', {  }, effects.fade_seconds, function() {
			$main_box.html(html);
			
			$main_box.css({ 'width': '710px' });
			$wrapper.css({ 'height': $main_box.height() });
			
			$wrapper.effect('size', { to: { width: 1025 } }, function() {
				$main_box.effect('fade', {  }, effects.fade_seconds);
			});
		});
	});
}

$my_reservation_detail_block = $('table#my_reservation_detail_block');
$my_reservation_detail_block.find('button#delete_order').live('click', function() {
	var order_id = $(this).parent('td').attr('id');
	$.post(base_url + 'index.php/backend/customer/delete_order/' + order_id, function(data) {
		if (data == 'succeed') {
			load_my_reservation_detail_block(order_id);
		}
	});
});

/* 
 * module: import_scheduler_modal
 * location: main_box
 */
var is_in_import_generate = false;
$import_scheduler_modal = $('#import_scheduler_modal');

var import_scheduler_data =
{
	'uploadFileName': '',
	'task': 'upload',
	'progress': 0
};

$dashboard_box.find('button#import_scheduler').live('click', function() {
	if ($.cookie('import_scheduler_data')) {
		import_scheduler_data = JSON.parse($.cookie('import_scheduler_data'));
		import_scheduler_data['task'] = 'upload';
		
		if (import_scheduler_data['uploadFileName'] == '') {
			import_scheduler_data['progress'] = 0;
		} else {
			import_scheduler_data['progress'] = 100;
		}
	}
	
	$.cookie('import_scheduler_data', JSON.stringify(import_scheduler_data), { 'path': '/' });
	
	if (is_in_import_generate == false) {
		load_import_scheduler_modal();
	}
});

function load_import_scheduler_modal() {
	$.post(base_url + 'index.php/backend/admin/load_import_scheduler_modal', function(html) {
		$sidebar_box1.find('div.modal-body').html(html);
	});
}

$import_scheduler_modal.find('button#import_scheduler_generate').live('click', function() {
	import_scheduler_data = JSON.parse($.cookie('import_scheduler_data'));
	import_scheduler_data['task'] = 'generate';
	import_scheduler_data['progress'] = 0;
	$.cookie('import_scheduler_data', JSON.stringify(import_scheduler_data), { 'path': '/' });
	
	load_import_scheduler_modal();
	setTimeout('import_scheduler_generate();', 100);
});

function import_scheduler_generate() {
	var xhr = new XMLHttpRequest();
	xhr.open('GET', base_url + 'index.php/backend/admin/import_scheduler_generate', true);
	xhr.send(null);
	var interval_id = window.setInterval(function() {
		$('body').append(xhr.responseText);
		is_in_import_generate = true;
		
		var progress_text;
		if (xhr.readyState <= 2) {
			progress_text = 'Initializing...';
		} else if (xhr.readyState == 3) {
			progress_text = 'Generating...';
		} else if (xhr.readyState == 4 && xhr.responseText.lastIndexOf('generate_succeed') == -1) {
			progress_text = 'Generating aborted. The Page will be reloaded immediately!';
			
			import_scheduler_data['task'] = 'upload';
			import_scheduler_data['progress'] = 100;
			$.cookie('import_scheduler_data', JSON.stringify(import_scheduler_data), { 'path': '/' });
			
			setTimeout('window.location.reload();', 2000);
		}
		
		if (xhr.responseText.lastIndexOf('generate_succeed') != -1) {
			is_in_import_generate = false;
			progress_text = 'Generating finished';
			
			import_scheduler_data['uploadFileName'] = '';
			import_scheduler_data['task'] = 'generate';
			import_scheduler_data['progress'] = 100;
			$.cookie('import_scheduler_data', JSON.stringify(import_scheduler_data), { 'path': '/' });
			load_import_scheduler_modal();
			window.clearInterval(interval_id);
		}
		//console.log(xhr.responseText);
		$import_scheduler_modal.find('.generate #progress_text strong').html(progress_text);
	}, 1000);
}

/* 
 * module: my_page_block
 * location: main_box
 */

$dashboard_box.find('button#my_page').live('click', function() {
	load_my_page_block();
	$booking_box.unblock();
});

function load_my_page_block() {
	$.post(base_url + 'index.php/backend/commons/get_user_info', function(html) {
		$main_box.effect('fade', {  }, effects.fade_seconds, function() {
			$main_box.html(html);
			
			$main_box.css({ 'width': '710px' });
			$wrapper.css({ 'height': $main_box.height() });
			
			$wrapper.effect('size', { to: { width: 1025 } }, function() {
				$main_box.effect('fade', {  }, effects.fade_seconds);
			});
		});
	});
}

$my_page_block = $('form#my_page_block');
$my_page_block.find('button#save').live('click', function() {
	$.post(base_url + 'index.php/backend/commons/save_user_info', $('form#my_page_block').serialize(), function(data) {
		if (data == 'succeed') {
			load_my_page_block();
		}
	});
});

$my_page_block.find('button#view_passengers').live('click', function() {
	load_my_page_passengers_block();
});

function load_my_page_passengers_block() {
	$.post(base_url + 'index.php/backend/customer/get_passengers', function(html) {
		$main_box.effect('fade', {  }, effects.fade_seconds, function() {
			$main_box.html(html);
			
			$main_box.css({ 'width': '710px' });
			$wrapper.css({ 'height': $main_box.height() });
			
			$wrapper.effect('size', { to: { width: 1025 } }, function() {
				$main_box.effect('fade', {  }, effects.fade_seconds);
			});
		});
	});
}

$my_page_passengers_block = $('table#my_page_passengers_block');
$my_page_passengers_block.find('button#edit_passenger').live('click', function() {
	var id = $(this).parent('td').attr('id');
	load_my_page_passengers_edit_block(id);
});

function load_my_page_passengers_edit_block(id) {
	$.post(base_url + 'index.php/backend/customer/get_passenger', { 'id': id }, function(html) {
		$main_box.effect('fade', {  }, effects.fade_seconds, function() {
			$main_box.html(html);
			
			$main_box.css({ 'width': '710px' });
			$wrapper.css({ 'height': $main_box.height() });
			
			$wrapper.effect('size', { to: { width: 1025 } }, function() {
				$main_box.effect('fade', {  }, effects.fade_seconds);
			});
		});
	});
}

$my_page_passengers_block.find('button#delete_passenger').live('click', function() {
	$.post(base_url + 'index.php/backend/customer/delete_passenger', { 'id': $(this).parent('td').attr('id') }, function(data) {
		if (data == 'succeed') {
			load_my_page_passengers_block();
		}
	});
});

$my_page_passenger_edit_block = $('form#my_page_passenger_edit_block');
$my_page_passenger_edit_block.find('button#save').live('click', function() {
	$.post(base_url + 'index.php/backend/customer/save_passenger', $('form#my_page_passenger_edit_block').serialize(), function(data) {
		if (data == 'succeed') {
			load_my_page_passengers_block();
		}
	});
});

$my_page_passenger_edit_block.find('button#view_passengers').live('click', function() {
	load_my_page_passengers_block();
});

//$.cookie('booking_box', null);
//$.cookie('select_flights', null);





